<template>
  <div class="app-container">
    <!-- 查询条件开始 -->
    <el-form
        ref="queryForm"
        :model="queryParams"
        :inline="true"
        label-width="98px"
    >
      <el-form-item label="医生姓名" prop="name">
        <el-input
            v-model="queryParams.name"
            placeholder="请输入医生姓名"
            clearable
            size="small"
            style="width: 180px"
        />
      </el-form-item>

      <el-form-item label="创建时间" prop="center">
        <el-date-picker
            v-model="queryParams.dateRange"
            size="small"
            style="width: 240px"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholde="开始日期"
            end-placeholde="结束日期"
        />
      </el-form-item>
      <el-form-item>
        <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
        >搜索</el-button
        >
        <el-button
            type="primary"
            icon="el-icon-refresh"
            size="mini"
            @click="resetQuery"
        >重置</el-button
        >
        <el-button
            type="danger"
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
        >批量删除</el-button>
      </el-form-item>
    </el-form>
    <!-- 查询条件结束 -->

    <!-- 数据表格开始 -->
    <el-table
        v-loading="loading"
        border
        :data="commentTableList"
        @selection-change="handleSelectionChnage($event)"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="评论序号" align="center" prop="id" />
      <el-table-column label="医生名称" align="center" prop="name">
      </el-table-column>
      <el-table-column label="评论内容" align="center" prop="content"  />
      <el-table-column label="评分" align="center" >
        <template slot-scope="scope">
          <el-rate
              v-model="scope.row.star"
              :colors="colors"
              show-text
              disabled
          ></el-rate>
        </template>
      </el-table-column>

      <el-table-column label="类型" prop="type" align="center">{{commnetType }}</el-table-column>
      <el-table-column label="创建时间" align="center" prop="addTime" />
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
              type="text"
              icon="el-icon-delete"
              size="mini"
              :disabled="single"
              @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 数据表格结束 -->
    <!-- 分页控件开始 -->
    <el-pagination
        :current-page="queryParams.pageNum"
        :page-sizes="[5,10, 15, 20]"
        :page-size="queryParams.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
    />
    <!-- 分页控件结束 -->
  </div>
</template>
<script>
import axios from "axios";

export default {
  // 定义页面数据
  data() {
    return {
      // 是否启用遮罩层
      loading: false,
      // 选中数组
      ids: [],
      valueIds:[],
      // 非单个禁用
      single: false,
      // 非多个禁用
      multiple: true,
      // 分页数据总条数
      total: 0,
      // 字典表格数据
      commentTableList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态数据字典
      // statusOptions: [],
      // 类型数据字典
      typeOptions: [],
      // 时间条件
      dateRange: [],
      // 查询参数
      //评论几颗星
      colors: ["#99A9BF", "#F7BA2A", "#FF9900"],

      queryParams: {
        pageNum: 1,
        pageSize: 5,
        dateRange: undefined,
        name:undefined,
      },
      docName: undefined,
      commnetType: undefined,
    };
  },
  // 勾子
  created() {
    // 使用全局的根据字典类型查询字典数据的方法查询字典数据
    // getDictDataAPI("sys_normal_disable").then((res) => {
    //   this.statusOptions = res.data;
    // });
    // 查询表格数据
    this.getProducterList();
  },
  // 方法
  methods: {
    // 查询表格数据
    getProducterList() {
      this.$http.post("/comment/show1", this.queryParams).then(res=>{
        //console.log(res.data.data)
        let array = res.data.data.data.list;
        array.forEach(item=>{
          if (item.type===0){
            this.commnetType='对医生评论'
          }else if (item.type===1){
            this.commnetType='专题评论'
          }else if (item.type===2){
            this.commnetType='普通评论'
          }
        });
        this.commentTableList = res.data.data.data.list;
        this.total = res.data.data.data.total;
      })
    },


    // 条件查询
    handleQuery() {
      this.getProducterList();
    },
    // 重置查询条件
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 5
      };
      this.getProducterList();
    },

    // 数据表格的多选择框选择时触发
    handleSelectionChnage(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length >1;
      this.multiple = !selection.length;
    },
    // 分页pageSize变化时触发
    handleSizeChange(val) {
      this.queryParams.pageSize = val;
      // 重新查询
      this.getProducterList();
    },
    // 点击上一页  下一页，跳转到哪一页面时触发
    handleCurrentChange(val) {
      this.queryParams.pageNum = val;
      // 重新查询
      this.getProducterList();
    },

    // 执行删除
    handleDelete(row) {
     let valueIds =  row.id || this.ids;
     // console.log(valueIds)
      this.$confirm("确认删除选中的项吗？,是否继续？", "提示", {
        confirmButtonText:"确定",
        cancelButtonText:"取消",
        type: "warning",
      }).then(()=>{
        // this.$http.post("/comment/deleteByIds?id="+valueIds, JSON.stringify(valueIds)).then(resp=>{
        //   if (resp.data.code===200){
        //    // console.log(this.valueIds)
        //     this.$message.success("删除成功");
        //     this.getProducterList();// 重新查询
        //   }
        //  })

        axios({
          method: "post",
          url: "/comment/deleteByIds?id="+valueIds,
          data: JSON.stringify(valueIds),
          headers:{
            "Content-Type":"application/json"
          }
        }).then(resp=>{
          if (resp.data.code===200){
            this.$message.success("删除成功");
            this.getProducterList();// 重新查询
          }
        })
        }).catch(error=>{
        this.$message.warning("取消删除");
      })
    },
  },
};
</script>
